package com.black.cat.utils;

import com.black.cat.lang.Nullable;

import java.util.Comparator;
import java.util.Map;


public class AntPathMatcher implements PathMatcher {

    public static final String DEFAULT_PATH_SEPARATOR = "/";


    private String pathSeparator;

    private boolean caseSensitive = true;

    private boolean trimTokens = false;



    @Override
    public boolean isPattern(String path) {
        return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
    }

    @Override
    public boolean match(String pattern, String path) {
        return doMatch(pattern, path, true, null);
    }

    protected boolean doMatch(String pattern, String path, boolean fullMatch,
                              @Nullable Map<String, String> uriTemplateVariables) {

        if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
            return false;
        }

        String[] pattDirs = tokenizePath(pattern);

//        if (fullMatch && this.caseSensitive && !isPotentialMatch(path, pattDirs)) {
//            return false;
//        }

        String[] pathDirs = tokenizePath(path);


        return true;
    }


    protected String[] tokenizePath(String path) {
        return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
    }

    @Override
    public boolean matchStart(String pattern, String path) {
        return doMatch(pattern, path, false, null);
    }

    @Override
    public String extractPathWithinPattern(String pattern, String path) {
        return null;
    }

    @Override
    public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
        return null;
    }

    @Override
    public Comparator<String> getPatternComparator(String path) {
        return null;
    }

    @Override
    public String combine(String pattern1, String pattern2) {
        return null;
    }
}
